<?php

namespace services\demo\service;

use \services\demo\data\UserSession;
use \services\demo\model\User;

use \services\demo\model\BaseService;
use \core\ServiceInvoke;

/**
 * 示例服务
 * @author kevin
 *
 */
class Demo extends BaseService {
	
	public function execute($trace_id, $current_trace_span_id, $request) {
		//soa_info ( 'request=' . var_export ( $request, TRUE ) );
		
		$request_params = get_status_code('0'); 
		$request_params ["message"] = "hello world";
		$request_params ["time"] = date('H:i:s');
		
		if (isset ( $request ["sid"] )) {
			$sid = $request ["sid"];
			$userSession = User::getUserSessionBySID ( $sid );
			if ($userSession != null) {
				$request_params ["nickname"] = $userSession->getNickName();
				$request_params ["ip"] = $userSession->getIP();
				$request_params ["email"] = $userSession->getEmail();
				$request_params ["app_version"] = $userSession->getAppVersion();
				$request_params ["logintime"] = $userSession->getLogintime();
			}
		}
		
		if (isset ( $request ["duangid"] )) {
			$resp = ServiceInvoke::invokeSoaService('com/dang/wireless', 'duang', '1.0', 
					$trace_id, $current_trace_span_id,
					array('duangid' => $request ["duangid"]));
			if(!is_null($resp)){
				$request_params ["duangname"] = $resp['data']['duangname'];
			}
		}
		
		if (isset ( $request ["huangid"] )) {
			$resp = ServiceInvoke::invokeSoaService('com/dang/wireless', 'huang', '1.0',
					$trace_id, $current_trace_span_id,
					array('huangid' => $request ["huangid"]));
			if(!is_null($resp)){
				$request_params ["huangname"] = $resp['data']['huangname'];
			}
		}
		
		//soa_info ( 'response=' . var_export ( $request_params, TRUE ) );
		return array('statusCode'=>'0','statusDesc'=>'','data'=>$request_params);
	}
	
}

